from pymysql import Connection

conn = Connection(
    host="localhost",
    port=3306,
    user="root",
    password="ahj7789t",
)

print(conn.get_server_info()) # 获取服务器版本信息

cursor = conn.cursor() # 创建游标
conn.select_db('food_kg')

#录入列表
ingrediants = ['土豆','洋葱','西红柿','胡萝卜','青椒','香菜','白糖','菠菜']
for i in range(len(ingrediants)):
    cursor.execute("insert into ingrediant values('%s','%d')" % (ingrediants[i],i+14))
    #注意这里的参数
conn.commit()

cursor.close()

conn.close()